# -*- coding:utf-8 -*-
from com.zzh.utils.dbUtils import MysqlUtils
from com.zzh.utils.table2Json_v2 import Table2Json


class CounselorDao(object):
    def __init__(self):
        self.conn = MysqlUtils.get_mysql_connections_v2()

    def insertCounselor(self, info):
        """
        添加 counselor 信息
        :param info:
        :return:
        """
        counName = info['counName']
        counPhone = info['counPhone']
        counAddress = info['counAddress']
        cur = self.conn.cursor()

        sql1 = "select * from zzh_counselor WHERE coun_phone=%s"
        rs1 = cur.execute(sql1, [counPhone])
        if rs1:
            return 0
        else:
            sql2 = "insert into zzh_counselor (coun_name, coun_phone, coun_address) VALUES " \
                   "(%s, %s, %s)"
            rs2 = cur.execute(sql2, [counName, counPhone, counAddress])
            self.conn.commit()
            cur.close()
            self.conn.close()
            if rs2:
                return 1
            else:
                return -1
